<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('分配道具-选择道具')" />
</head>

<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
					<input type="hidden" id="shopId" name="shopId" th:value="${fantasyShop.id}">
					<div class="select-list">
						<ul>
							<li>
								道具名称：<input type="text" name="name"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var datas = [[${@dict.getType('sys_normal_disable')}]];
        var prefix = ctx + "fantasy/fantasyShop/allocItem";
		var itemType = [[${@dict.getType('shop_type')}]];

		$(function() {
			var options = {
		        url: prefix + "/unallocatedList",
		        queryParams: queryParams,
		        sortName: "createTime",
		        sortOrder: "desc",
		        modalName: "Item",
		        showSearch: false,
		        showRefresh: false,
		        showToggle: false,
		        showColumns: false,
		        clickToSelect: true,
		        rememberSelected: true,
		        columns: [{
		            checkbox: true
		        },
				{
					field: 'id',
					title: '道具 ID',
					visible: false,
				},
				{
					field : 'name',
					title : '名称',
					sortable: true
				},
				{
					field : 'itemType',
					title : '类型',
					sortable: true,
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(itemType, value);
					}
				},
				{
					field : 'rarelyStr',
					title : '稀有',
					sortable: true
				},
				{
					field : 'imgsrc',
					title : '道具图片',
					sortable: true,
					formatter: showImg,
					events: 'operateEvents'
				},
				{
					field : 'itemLevel',
					title : '道具等级',
					sortable: true
				},
				{
					field : 'itemDesc',
					title : '描述',
					sortable: false
				}]
		    };
		    $.table.init(options);
		});

		function queryParams(params) {
			var search = $.table.queryParams(params);
			search.id = $("#shopId").val();
			return search;
		}
		
		/* 添加道具-选择道具-提交 */
		function submitHandler() {
			var rows = $.table.selectFirstColumns();
			if (rows.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
			var data = { "shopId": $("#shopId").val(), "itemIds": rows.join() };
			$.operate.save(prefix + "/selectAll", data);
		}


		function showImg(value, row, index) {
			var imgSrc = ctx + 'profile/' + value;
			var s = '<a class = "view"  href="javascript:void(0)"><img style="width:30px;height:30px;"  src="'+imgSrc+'" /></a>';
			return s;
		}

		window.operateEvents = {
			'click .view': function (e, value, row, index) {
				var imgSrc = ctx + 'profile/' + value;
				layer.open({
					type: 1,
					title: false,
					closeBtn: 0,
					area: 'auto',
					skin: 'layui-layer-nobg', //没有背景色
					shadeClose: true,
					content: '<img src="'+imgSrc+'"/>'
				});
			},
		};
	</script>
</body>
</html>